home *** CD-ROM | disk | FTP | other *** search
/ The CICA Windows Explosion! / The CICA Windows Explosion! - Disc 2.iso / programr / ole2book.zip / CHAP11.ZIP / CHAP11 / COSCHMOO / IADVSINK.CPP < prev    next >
C/C++ Source or Header  |  1993-06-13  |  8KB  |  404 lines

  1. /*
  2.  * IADVSINK.CPP
  3.  *
  4.  * Implementation of the CPolylineAdviseSink and CImpIAdviseSink interfaces
  5.  * for Component Schmoo.  CPolylineAdviseSink moved here from polyline.cpp
  6.  * to live with all the advise stuff.
  7.  *
  8.  * IAdviseSink is implemented as a stand-alone object since no other piece
  9.  *
  10.  *
  11.  * Copyright (c)1993 Microsoft Corporation, All Rights Reserved
  12.  *
  13.  * Kraig Brockschmidt, Software Design Engineer
  14.  * Microsoft Systems Developer Relations
  15.  *
  16.  * Internet  :  kraigb@microsoft.com
  17.  * Compuserve:  >INTERNET:kraigb@microsoft.com
  18.  */
  19.  
  20.  
  21. #include "coschmoo.h"
  22.  
  23.  
  24. /*
  25.  * CPolylineAdviseSink::CPolylineAdviseSink
  26.  * CPolylineAdviseSink::~CPolylineAdviseSink
  27.  *
  28.  * Constructor Parameters:
  29.  *  pv              LPVOID to store in this object
  30.  *  punkOuter       LPUNKNOWN for IUnknown member delegation
  31.  */
  32.  
  33. CPolylineAdviseSink::CPolylineAdviseSink(LPVOID pv, LPUNKNOWN punkOuter)
  34.     {
  35.     m_cRef=0;
  36.     m_pv=pv;
  37.     m_punkOuter=punkOuter;
  38.     return;
  39.     }
  40.  
  41.  
  42. CPolylineAdviseSink::~CPolylineAdviseSink(void)
  43.     {
  44.     return;
  45.     }
  46.  
  47.  
  48.  
  49.  
  50. /*
  51.  * CPolylineAdviseSink::QueryInterface
  52.  * CPolylineAdviseSink::AddRef
  53.  * CPolylineAdviseSink::Release
  54.  *
  55.  * Purpose:
  56.  *  IUnknown members for this IPolylineAdviseSink implementations.
  57.  */
  58.  
  59. STDMETHODIMP CPolylineAdviseSink::QueryInterface(REFIID riid, LPVOID FAR *ppv)
  60.     {
  61.     return m_punkOuter->QueryInterface(riid, ppv);
  62.     }
  63.  
  64.  
  65. STDMETHODIMP_(ULONG) CPolylineAdviseSink::AddRef(void)
  66.     {
  67.     ++m_cRef;
  68.     return m_punkOuter->AddRef();
  69.     }
  70.  
  71.  
  72. STDMETHODIMP_(ULONG) CPolylineAdviseSink::Release(void)
  73.     {
  74.     --m_cRef;
  75.     return m_punkOuter->AddRef();
  76.     }
  77.  
  78.  
  79.  
  80.  
  81. /*
  82.  * CPolylineAdviseSink::OnPointChange
  83.  *
  84.  * Purpose:
  85.  *  Informs the document that the polyline added or removed a point.
  86.  *
  87.  * Parameters:
  88.  *  None
  89.  *
  90.  * Return Value:
  91.  *  None
  92.  */
  93.  
  94. STDMETHODIMP_(void) CPolylineAdviseSink::OnPointChange(void)
  95.     {
  96.     LPCDocument pDoc=(LPCDocument)m_pv;
  97.  
  98.     pDoc->FDirtySet(TRUE);
  99.     return;
  100.     }
  101.  
  102.  
  103.  
  104.  
  105.  
  106.  
  107. /*
  108.  * CPolylineAdviseSink::OnSizeChange
  109.  *
  110.  * Purpose:
  111.  *  Informs the document that the polyline changed size.
  112.  *
  113.  * Parameters:
  114.  *  None
  115.  *
  116.  * Return Value:
  117.  *  None
  118.  */
  119.  
  120. STDMETHODIMP_(void) CPolylineAdviseSink::OnSizeChange(void)
  121.     {
  122.     LPCSchmooDoc pDoc=(LPCSchmooDoc)m_pv;
  123.     RECT         rc;
  124.     DWORD        dwStyle;
  125.     HWND         hWnd;
  126.  
  127.     /*
  128.      * Polyline window is informing us that it changed size in
  129.      * response to setting it's data.  Therefore we have to
  130.      * size ourselves accordingly but without moving the screen
  131.      * position of the polyline window.
  132.      */
  133.  
  134.     pDoc->m_fNoSize=TRUE;
  135.  
  136.     //Set the document window size.
  137.     pDoc->m_pPL->Window(&hWnd);
  138.     GetWindowRect(hWnd, &rc);
  139.     InflateRect(&rc, 8, 8);
  140.  
  141.     //Adjust for a window sans menu
  142.     dwStyle=GetWindowLong(pDoc->m_hWnd, GWL_STYLE);
  143.     AdjustWindowRect(&rc, dwStyle, FALSE);
  144.  
  145.     SetWindowPos(pDoc->m_hWnd, NULL, 0, 0, rc.right-rc.left
  146.         , rc.bottom-rc.top, SWP_NOMOVE | SWP_NOZORDER);
  147.  
  148.     if (NULL!=pDoc->m_pAdv)
  149.         pDoc->m_pAdv->OnSizeChange(pDoc, &rc);
  150.  
  151.     pDoc->m_fNoSize=FALSE;
  152.     pDoc->FDirtySet(TRUE);
  153.  
  154.     return;
  155.     }
  156.  
  157.  
  158.  
  159.  
  160.  
  161. /*
  162.  * CPolylineAdviseSink::OnColorChange
  163.  *
  164.  * Purpose:
  165.  *  Informs the document that the polyline data changed a color.
  166.  *
  167.  * Parameters:
  168.  *  None
  169.  *
  170.  * Return Value:
  171.  *  None
  172.  */
  173.  
  174. STDMETHODIMP_(void) CPolylineAdviseSink::OnColorChange(void)
  175.     {
  176.     LPCSchmooDoc    pDoc=(LPCSchmooDoc)m_pv;
  177.  
  178.     pDoc->FDirtySet(TRUE);
  179.     return;
  180.     }
  181.  
  182.  
  183.  
  184.  
  185.  
  186. /*
  187.  * CPolylineAdviseSink::OnLineStyleChange
  188.  *
  189.  * Purpose:
  190.  *  Informs the document that the polyline changed its line style.
  191.  *
  192.  * Parameters:
  193.  *  None
  194.  *
  195.  * Return Value:
  196.  *  None
  197.  */
  198.  
  199. STDMETHODIMP_(void) CPolylineAdviseSink::OnLineStyleChange(void)
  200.     {
  201.     LPCSchmooDoc    pDoc=(LPCSchmooDoc)m_pv;
  202.  
  203.     pDoc->FDirtySet(TRUE);
  204.     return;
  205.     }
  206.  
  207.  
  208.  
  209.  
  210.  
  211.  
  212.  
  213.  
  214.  
  215.  
  216.  
  217.  
  218. /*
  219.  * CImpIAdviseSink::CImpIAdviseSink
  220.  * CImpIAdviseSink::~CImpIAdviseSink
  221.  *
  222.  * Parameters (Constructor):
  223.  *  pObj            LPVOID of the object we're in.
  224.  *  punkOuter       LPUNKNOWN for delegation of IUnknown members.
  225.  */
  226.  
  227. CImpIAdviseSink::CImpIAdviseSink(LPVOID pObj, LPUNKNOWN punkOuter)
  228.     {
  229.     m_cRef=0;
  230.     m_pObj=pObj;
  231.     m_punkOuter=punkOuter;
  232.     return;
  233.     }
  234.  
  235. CImpIAdviseSink::~CImpIAdviseSink(void)
  236.     {
  237.     return;
  238.     }
  239.  
  240.  
  241.  
  242.  
  243. /*
  244.  * CImpIAdviseSink::QueryInterface
  245.  * CImpIAdviseSink::AddRef
  246.  * CImpIAdviseSink::Release
  247.  *
  248.  * Purpose:
  249.  *  IUnknown members for CImpIAdviseSink object.
  250.  */
  251.  
  252. STDMETHODIMP CImpIAdviseSink::QueryInterface(REFIID riid, LPVOID FAR *ppv)
  253.     {
  254.     return m_punkOuter->QueryInterface(riid, ppv);
  255.     }
  256.  
  257.  
  258. STDMETHODIMP_(ULONG) CImpIAdviseSink::AddRef(void)
  259.     {
  260.     ++m_cRef;
  261.     return m_punkOuter->AddRef();
  262.     }
  263.  
  264. STDMETHODIMP_(ULONG) CImpIAdviseSink::Release(void)
  265.     {
  266.     --m_cRef;
  267.     return m_punkOuter->AddRef();
  268.     }
  269.  
  270.  
  271.  
  272.  
  273. /*
  274.  * IAdviseSink::OnDataChange
  275.  *
  276.  * Purpose:
  277.  *  Notifes the advise sink that data changed in a data object.  On
  278.  *  this message you may request a new data rendering and update your
  279.  *  displays as necessary.
  280.  *
  281.  * Parameters:
  282.  *  pFEIn           LPFORMATETC describing format that changed
  283.  *  pSTM            LPSTGMEDIUM providing the medium in which the data
  284.  *                  is provided.
  285.  *
  286.  * Return Value:
  287.  *  None
  288.  */
  289.  
  290. STDMETHODIMP_(void) CImpIAdviseSink::OnDataChange(LPFORMATETC pFEIn
  291.     , LPSTGMEDIUM pSTM)
  292.     {
  293.     LPCSchmooDoc    pDoc=(LPCSchmooDoc)m_pObj;
  294.  
  295.     /*
  296.      * This code copied from former CPolylineAdviseSink::OnDataChange.
  297.      * The only advise we asked for was on the Polyline native format
  298.      * which is all we'll be notified for.
  299.      */
  300.     if (NULL!=pDoc->m_pAdv)
  301.         pDoc->m_pAdv->OnDataChange(pDoc);
  302.  
  303.     pDoc->FDirtySet(TRUE);
  304.     return;
  305.     }
  306.  
  307.  
  308.  
  309.  
  310.  
  311. /*
  312.  * IAdviseSink::OnViewChange
  313.  *
  314.  * Purpose:
  315.  *  Notifes the advise sink that presentation data changed in the data
  316.  *  object to which we're connected providing the right time to update
  317.  *  displays using such presentations.
  318.  *
  319.  * Parameters:
  320.  *  dwAspect        DWORD indicating which aspect has changed.
  321.  *  lindex          LONG indicating the piece that changed.
  322.  *
  323.  * Return Value:
  324.  *  None
  325.  */
  326.  
  327. STDMETHODIMP_(void) CImpIAdviseSink::OnViewChange(DWORD dwAspect, LONG lindex)
  328.     {
  329.     return;
  330.     }
  331.  
  332.  
  333.  
  334.  
  335.  
  336. /*
  337.  * IAdviseSink::OnRename
  338.  *
  339.  * Purpose:
  340.  *  Informs the advise sink that an IOleObject has been renamed, primarily
  341.  *  when its linked.
  342.  *
  343.  * Parameters:
  344.  *  pmk             LPMONIKER providing the new name of the object
  345.  *
  346.  * Return Value:
  347.  *  None
  348.  */
  349.  
  350. STDMETHODIMP_(void) CImpIAdviseSink::OnRename(LPMONIKER pmk)
  351.     {
  352.     return;
  353.     }
  354.  
  355.  
  356.  
  357.  
  358.  
  359.  
  360. /*
  361.  * IAdviseSink::OnSave
  362.  *
  363.  * Purpose:
  364.  *  Informs the advise sink that the OLE object has been saved
  365.  *  persistently.  The primary purpose of this is for containers that
  366.  *  want to make optimizations for objects that are not in a saved
  367.  *  state, so on this you have to disable such optimizations.
  368.  *
  369.  * Parameters:
  370.  *  None
  371.  *
  372.  * Return Value:
  373.  *  None
  374.  */
  375.  
  376. STDMETHODIMP_(void) CImpIAdviseSink::OnSave(void)
  377.     {
  378.     return;
  379.     }
  380.  
  381.  
  382.  
  383.  
  384.  
  385. /*
  386.  * IAdviseSink::OnClose
  387.  *
  388.  * Purpose:
  389.  *  Informs the advise sink that the OLE object has closed and is
  390.  *  no longer bound in any way.  On this you typically change state
  391.  *  variables and redraw shading, etc.
  392.  *
  393.  * Parameters:
  394.  *  None
  395.  *
  396.  * Return Value:
  397.  *  None
  398.  */
  399.  
  400. STDMETHODIMP_(void) CImpIAdviseSink::OnClose(void)
  401.     {
  402.     return;
  403.     }
  404.